Skip to content

Commit

Permalink
add topology
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyuli committed May 5, 2015
1 parent 49ddc2e commit 7d8f607
Show file tree
Hide file tree
Showing 37 changed files with 831 additions and 341 deletions.
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) zhengyu li, 2015.
Copyright (C) 2014-2016 zhengyu li <[email protected]>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES (
util
logger
app_service/
topology/
ownership/
management/
protocol/
Expand All @@ -50,6 +51,8 @@ SET (NTRACE_SOURCE_FILES
task_manager.c
app_service/app_service.c
app_service/app_service_manager.c
topology/topology_entry.c
topology/topology_manager.c
netdev.c
management/management_service.c
ownership/ownership.c
Expand Down
34 changes: 21 additions & 13 deletions src/app_service/app_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,36 @@ newAppServiceInternal (void) {
* @brief Create new appService.
* Create new appService from proto, ip and port.
*
* @param proto appService proto name
* @param ip appService ip address
* @param port appService port
* @param proto appService proto name
*
* @return appService if success, else NULL
*/
appServicePtr
newAppService (char *proto, char *ip, u_short port) {
newAppService (char *ip, u_short port, char *proto) {
protoAnalyzerPtr analyzer;
appServicePtr svc;

svc = newAppServiceInternal ();
if (svc == NULL)
return NULL;

analyzer = getProtoAnalyzer (proto);
if (analyzer == NULL) {
LOGE ("Unsupported appService proto type: %s.\n", proto);
free (svc);
return NULL;
if (proto) {
analyzer = getProtoAnalyzer (proto);
if (analyzer == NULL) {
LOGE ("Unsupported appService proto type: %s.\n", proto);
free (svc);
return NULL;
}

svc->proto = analyzer->proto;
svc->analyzer = analyzer;
} else {
svc->proto = "UNKNOWN";
svc->analyzer = NULL;
}
svc->proto = analyzer->proto;
svc->analyzer = analyzer;

svc->ip = strdup (ip);
if (svc->ip == NULL) {
svc->analyzer = NULL;
Expand All @@ -66,6 +73,7 @@ freeAppService (appServicePtr svc) {
if (svc == NULL)
return;

svc->proto = NULL;
svc->analyzer = NULL;
free (svc->ip);
svc->ip = NULL;
Expand All @@ -74,7 +82,7 @@ freeAppService (appServicePtr svc) {

void
freeAppServiceForHash (void *data) {
return freeAppService ((appServicePtr) data);
freeAppService ((appServicePtr) data);
}

/**
Expand Down Expand Up @@ -122,11 +130,11 @@ appService2Json (appServicePtr svc) {
return NULL;
}

/* appService proto */
/* AppService proto */
json_object_set_new (root, APP_SERVICE_PROTO, json_string (svc->proto));
/* appService ip */
/* AppService ip */
json_object_set_new (root, APP_SERVICE_IP, json_string (svc->ip));
/* appService port */
/* AppService port */
json_object_set_new (root, APP_SERVICE_PORT, json_integer (svc->port));

return root;
Expand Down
2 changes: 1 addition & 1 deletion src/app_service/app_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct _appService {

/*========================Interfaces definition============================*/
appServicePtr
newAppService (char *proto, char *ip, u_short port);
newAppService (char *ip, u_short port, char *proto);
void
freeAppService (appServicePtr svc);
appServicePtr
Expand Down
Loading

0 comments on commit 7d8f607

Please sign in to comment.